<?php

class ConferenceController extends Zend_Controller_Action 
{
    protected $_model;

    public function init()
    {
        $ajaxContext = $this->_helper->getHelper('AjaxContext');
        $ajaxContext->addActionContext('view', 'html')
                    ->addActionContext('comment', 'html')                    
                    ->initContext();
    }
    
    public function indexAction()
    {
  
    }
    public function allAction()
    {
    	$request = $this->getRequest();
    	$callback = $request->getParam('callback');
        $model = $this->_getModel();		
        $conferences = $model->fetchEntries();
		$count = count($conferences);
        $json = array();
        $json['totalCount'] = $count;
        $json['conferences'] = $conferences;
        echo $callback.'('.Zend_Json::encode($json).')';
        die();
    }
    public function viewAction()
    {
        $model = $this->_getModel();
        $request = $this->getRequest();
        $id = $request->getParam('id');
        $this->view->post = $model->fetchEntry($id);   
        $model = $this->getCommentModel();                 
        $this->view->comments = $model->fetchEntries();             
    }

	public function editAction()
    {        
		$request = $this->getRequest();
		
        if ($this->getRequest()->isPost()) {
			$model = $this->_getModel();
			$data = $request->getParams();
			$model->save($data);
		}
        die();
    }
	
    public function deleteAction(){
    	$model = $this->_getModel();
      	$request = $this->getRequest();
	    $id = $request->getParam('id'); 
      	$model->deleteConference($id);
    	die();
    } 
    public function setactiveAction(){
        $model = $this->_getModel();
      	$request = $this->getRequest();
	    $id = $request->getParam('id'); 
      	$model->setActive($id);
        die();
    }    
    protected function _getModel()
    {
        if (null === $this->_model) {
            require_once APPLICATION_PATH . '/models/Conference.php';
            $this->_model = new Model_Conference();
        }
        return $this->_model;
    }
}
